<html>
<head>
<title>Capture Page</title>
</head>
<body>
<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script>

<script language="JavaScript" type="text/javascript">
<!--
alert("yes!!! this is the new version of the capture page");
var localServer = google.gears.factory.create('beta.localserver');
var store = localServer.createStore('test-store');
var whichCap;

captureId=store.capture("http://localhost:8080/testpage/capture.html",ourCallback);
alert("capture id for capture page is "+captureId);

captureId=store.capture("http://localhost:8080/images/banga.png",ourCallback);
alert("capture id for banga pic is "+captureId);

var manifest;
var currentCard=0;
var cardNamesMostly;

function run()
{
	var req = new XMLHttpRequest();  
	try
	{
 	req.open('GET', 'http://localhost:8080/dm0?joe', false);   
 	req.send(null);  
	}
	catch(e)
	{
		alert("offline, we think");
		deckName="newdeck";
		var req4 = new XMLHttpRequest();
		req4.open('GET', 'http://localhost:8080/manifest?'+deckName, false); 
		req4.send(null);  
		alert("request for manifest status offline "+req4.status);
 		if(req4.status == 200) 
		{
			manifest=req4.responseText;
		}

		
	}
	alert("in run req status ",req.status);
 	if(req.status == 200) 
	{
		alert("command: <"+req.responseText+">"); 
		pieces=req.responseText.split(" ");
		deckName=pieces[3];
		alert("deckName "+deckName);
		captureId=store.capture("http://localhost:8092/manifest?"+deckName,ourCallback);
		alert("capture id for manifest: ",captureId);
		var req2 = new XMLHttpRequest();
		req2.open('GET', 'http://localhost:8092/manifest?'+deckName, false); 
		req2.send(null);  
		alert("request for manifest status "+req2.status);
 		if(req2.status == 200) 
		{
			manifest=req2.responseText;
			cardNamesMostly=manifest.split("*");
			for (i=1;i<cardNamesMostly.length;i++)
			{
				alert("card name in loop: "+cardNamesMostly[i]);
				captureId=store.capture("http://localhost:8092/image?"+cardNamesMostly[i],ourCallback);
				captureId=store.capture("http://localhost:8080/hint?"+cardNamesMostly[i],ourCallback);
			}
		}
	}
	
}
function nextCard()
{
	cardNamesMostly=manifest.split("*");
	currentCard=currentCard+1;
	alert("currentCard name: "+cardNamesMostly[currentCard]);
	document.images[0].src="http://localhost:8080/image?"+cardNamesMostly[currentCard];
	hintBox=document.getElementById("hint");
	var req3 = new XMLHttpRequest();
	req3.open('GET', 'http://localhost:8080/hint?'+cardNamesMostly[currentCard], false); 
	req3.send(null);  
	hintBox.value=req3.responseText;
}
	

function ourCallback(url, success, captureId)
{
	alert("callback "+captureId);
}
//-->
</script>
<input type="button" value="run" onclick="run()">
<input type="button" value="next card" onclick="nextCard()">
<img src="../images/banga.png">
<input type="text" id="hint" value="---------" >
</body>
</html>
